//
//  MLBleFunctionViewController.m
//  MLBleSDK
//
//  Created by 程杰 on 2023/10/19.
//

#import "MLBleFunctionViewController.h"
#import "FuncTableViewCell.h"
#import "MLDiscoverViewController.h"
@interface MLBleFunctionViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *arrays;
@end

@implementation MLBleFunctionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"蓝牙功能";
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tableView.rowHeight = UITableViewRowAnimationAutomatic;
    self.tableView.estimatedRowHeight = 70;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [UIView new];
    [self.view addSubview:self.tableView];
    
    [self.tableView reloadData];
    // 打开蓝牙通知
    
}
- (void)viewWillDisappear:(BOOL)animated {
    
    [[MLBLEManager sharedManager] disconnectFromPeripheral:self.model.peripheral];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.arrays.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FuncTableViewCell *cell = [FuncTableViewCell cellWithTableView:tableView];
    // 取消选中效果
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
     NSString *title = self.arrays[indexPath.row][@"title"];
     [cell.btnName setTitle:title forState:UIControlStateNormal];
    return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO]; // 取消选中效果
    if (indexPath.row == 0) {

        [self.navigationController pushViewController:[MLDiscoverViewController new] animated:YES];
        
    } else if (indexPath.row == 1) {
        
    }
    
}

- (NSArray *)arrays {
    if (_arrays == nil) {
        
        _arrays = [NSArray array];
        _arrays = @[
            @{@"title": @"BLEV2.0-行研"},
        ];
    }
    return _arrays;
}

@end
